
#include "ParsingFunctions.h"
#include <sstream>
#include <cstdlib>

namespace FileParser
{

namespace ParsingFunctions
{

template<>
Math::Vector2F Parse(const char* data)
{
    std::istringstream iss( data );
    double x, y;
    char garb;
    iss >> x;
    iss >> garb;
    iss >> y;
    Math::Vector2F result( x, y );
    return result;
}

template<>
gl::Color Parse(const char* data)
{
    std::istringstream iss( data );
    int r, g, b, a;
    char garb;
    iss >> r;
    iss >> garb;
    iss >> g;
    iss >> garb;
    iss >> b;
    iss >> garb;
    iss >> a;
    return gl::Color( r, g, b, a );
}

template<>
Math::Rect Parse(const char* data)
{
    std::istringstream iss( data );
    int top, left, width, height;
    char garb;
    iss >> top;
    iss >> garb;
    iss >> left;
    iss >> garb;
    iss >> width;
    iss >> garb;
    iss >> height;
    return Math::Rect( top, left, width, height );
}

template<>
bool Parse(const char* data)
{
    return( strcmp( data, "true" ) == 0 );
}

template<>
int Parse(const char* data)
{
    return std::atoi( data );
}

template<>
float Parse(const char* data)
{
    return std::atof( data );
}

template<>
double Parse(const char* data)
{
    return std::atof( data );
}

}
}
